package Homework_0709.src.practice2;

import java.util.function.Predicate;

/**
 * @author caesar
 * @date 2025/7/9
 * @Description:
 * @apiNote
 */
public class EmployeeService {
    private Employee[] arr = new Employee[5];
    private int total;

    public void add(Employee emp){
        if(total >= arr.length){
            System.out.println("数组已满，无法添加");
            return;
        }
        arr[total++] = emp;
    }

    public Employee[] get(Predicate p){
        int count = 0;
        for (int i=0; i<arr.length; i++) {
            if(p.test(arr[i])){
                count++;
            }
        }
        Employee[] result = new Employee[count];
        count = 0;
        for (int i=0; i<arr.length; i++) {
            if(p.test(arr[i])){
                result[count++] = arr[i];
            }
        }
        return result;
    }
}
